<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<table lay-filter="layerTable" lay-skin="line">
	<thead>
		<tr>
			<th class="xutd" lay-data="{field:'xutdId', width:60,fixed:'left'}">序号</th>
			<th lay-data="{field:'userName'}">用户名</th>
			<th lay-data="{field:'realName'}">姓名</th>
			<th lay-data="{field:'roleName'}">角色名称</th>
			<th lay-data="{field:'mobile'}">联系电话</th>
			<th lay-data="{field:'emailAddress'}">邮箱地址</th>
			<th lay-data="{field:'status'}">状态</th>
			<th lay-data="{field:'createTime',fixed:'right',sort:true}">创建时间</th>
			<th lay-data="{field:'seting', width:200,fixed:'right'}">操作</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${pager.result}" var="item" varStatus="index">
			<tr>
				<td>${(index.index+1)+pager.pageParameter.pageSize*(pager.pageParameter.current-1)}</td>
				<td>${item.systemUserName }</td>
				<td>${item.systemRealName }</td>
				<td>${item.roleNames }</td>
				<td>${item.systemCell}</td>
				<td>${item.systemEmail}</td>
				<td>
					<c:if test="${item.status == 'normal'}">正常</c:if> 
					<c:if test="${item.status == 'locked'}">锁定</c:if>
				</td>
				<td>${item.createTime}</td>
				<td>
				<shiro:hasPermission name="sysman:SYSTEM_ADMIN_MAN:edit">
					<button class="layui-btn layui-btn-small editBtn" type="button" data-id="${item.systemCode}" onclick="adminUpChange(this);">
						<i class="layui-icon" title="编辑">&#xe642;</i>
					</button>
				</shiro:hasPermission>
				<shiro:hasPermission name="sysman:SYSTEM_ADMIN_MAN:delete">
					<button class="layui-btn layui-btn-small layui-btn-danger delBtn" type="button" data-id="${item.systemCode}" onclick="toDel(this);">
						<i class="layui-icon" title="删除">&#xe640;</i>
					</button>
				</shiro:hasPermission>
				<shiro:hasPermission name="sysman:SYSTEM_ADMIN_MAN:resetPwd">
					<button class="layui-btn layui-btn-warm layui-btn-mini" type="button" data-id="${item.systemCode}" onclick="resertPwd(this);">重置密码</button>
				</shiro:hasPermission>
			</td>
			</tr>
		</c:forEach>
	</tbody>
</table>
<div id="layer-page"></div>
<input type="hidden" id="currentPage" value="${pager.pageParameter.current}" />
<input type="hidden" id="pageSize" value="${pager.pageParameter.pageSize}" />
<script type="text/javascript">
    layui.use(['table', 'laypage'], function(){
        var table = layui.table;
        //转换静态表格
        table.init('layerTable', {
            height: $(window).height() - 220, //设置高度,
            limit:${pager.pageParameter.pageSize}
        });
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
            elem: 'layer-page' //注意，这里的 test1 是 ID，不用加 # 号
            ,limits:[20,40,60,80,100,200]
            ,limit:${pager.pageParameter.pageSize}
            ,curr:${pager.pageParameter.current}
            ,count: ${pager.pageParameter.totalCount} //数据总数，从服务端得到
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            ,jump: function(obj, first){
                console.log(obj.curr);
                console.log(obj.limit);
                //首次不执行
                if(!first){
                    baseSearchQueryLayer(obj.curr,obj.limit);
                    //转换静态表格
                }
            }
        });

        window.onresize = function() {
            //转换静态表格
            table.init('layerTable', {
                height: $(window).height() - 220, //设置高度,
                limit:${pager.pageParameter.pageSize}
            });
        }
    });
	// 编辑用户
	function adminUpChange(obj){
		var adminId = $(obj).attr("data-id");
		var editlayer = layer.open({
	        type: 2,
	        title: false,
	        shadeClose: true,
	        shade: false,
	        maxmin: true, 
	        area: ['600px' , '250px'],
	        content:'${ctx}/sysman/systemAdmin/toChangeView.do?code='+adminId
	    });
		layer.full(editlayer);
	}
	//修改密码
	function resertPwd(obj){
        var adminId = $(obj).attr("data-id");
		layer.open({
	        type: 2,
	        title: false,
	        shadeClose: true,
	        shade: false,
	        maxmin: true, 
	        area: ['600px' , '250px'],
	        content: '${ctx}/sysman/systemAdmin/toResetPwd.do?systemCode='+adminId,
	    });
	}

    function toDel(obj){
        baseSelDel(obj);
    }

  </script>